<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<nz-tabset [nzSize]="'small'" [nzAnimated]="{ inkBar: true, tabPane: false }">
  <nz-tab nzTitle="Root Exception" nzForceRender>
    <flink-monaco-editor [value]="rootException"></flink-monaco-editor>
  </nz-tab>
  <nz-tab nzTitle="Exception History" nzForceRender>
    <nz-table
      class="no-border small"
      [nzSize]="'small'"
      [nzData]="exceptionHistory"
      [nzShowPagination]="false"
      [nzFrontPagination]="false"
    >
      <thead>
        <tr>
          <th nzWidth="60px"></th>
          <th>Time</th>
          <th>Exception</th>
          <th>Task Name</th>
          <th>Location</th>
        </tr>
      </thead>
      <tbody>
        <ng-container *ngFor="let item of exceptionHistory; trackBy: trackExceptionBy">
          <tr>
            <td nzShowExpand [(nzExpand)]="item.expand"></td>
            <td>{{ item.selected.timestamp | date: 'yyyy-MM-dd HH:mm:ss' }}</td>
            <td>
              <div class="name">{{ item.selected.exceptionName }}</div>
            </td>
            <td class="select-td">
              <nz-select
                class="exception-select"
                nzSize="small"
                [nzDisabled]="item.exceptions.length === 1"
                nzShowSearch
                [(ngModel)]="item.selected"
              >
                <nz-option
                  *ngFor="let ex of item.exceptions"
                  nzCustomContent
                  [nzLabel]="ex.taskName"
                  [nzValue]="ex"
                >
                  <span
                    nz-tooltip
                    [nzTooltipTitle]="ex.taskName"
                    nzTooltipMouseEnterDelay="0.5"
                    nzTooltipPlacement="left"
                  >
                    {{ ex.taskName }}
                  </span>
                </nz-option>
              </nz-select>
            </td>
            <td>{{ item.selected.location || '(unassigned)' }}</td>
          </tr>
          <tr [nzExpand]="item.expand">
            <td colspan="5" class="expand-td">
              <flink-monaco-editor
                *ngIf="item.expand"
                class="subtask"
                [value]="item.selected.stacktrace"
              ></flink-monaco-editor>
            </td>
          </tr>
        </ng-container>
        <tr *ngIf="exceptionHistory.length > 0">
          <td colspan="5">
            <i nz-icon nzType="info-circle" nzTheme="fill"></i>
            &nbsp;
            <i>
              The exception history is limited to the most recent failures that caused parts of the
              job or the entire job to restart. The maximum history size can be configured via the
              Flink configuration property
              <b>web.exception-history-size</b>
              .
            </i>
          </td>
        </tr>
        <tr *ngIf="truncated">
          <td colspan="5">
            <button
              nz-button
              nzBlock
              nzType="primary"
              nzGhost
              (click)="loadMore()"
              [nzLoading]="isLoading"
            >
              Load More
            </button>
          </td>
        </tr>
      </tbody>
    </nz-table>
  </nz-tab>
</nz-tabset>
